package com.royal.lr.util;

import org.apache.http.client.fluent.Request;
import org.apache.http.entity.ContentType;

import java.io.IOException;

public class SimpleHttp {
    private static final int connTimeout = 15 * 1000;
    private static final int socketTimeout = 30 * 1000;

    public static String doPost(String url, String jsonStr) throws Exception{
        try {
            return Request.Post(url).bodyString(jsonStr, ContentType.APPLICATION_JSON)
                    .connectTimeout(connTimeout).socketTimeout(socketTimeout).execute().returnContent().asString();
        } catch (Exception e) {
            throw e;
        }
    }

    public static String doGet(String url) throws Exception{
        try {
            return Request.Get(url)
                    .connectTimeout(connTimeout).socketTimeout(socketTimeout).execute()
                    .returnContent().asString();
        } catch (Exception e) {
            throw e;
        }
    }
}
